package com.web709.controller;

import com.web709.common.R;
import com.web709.entity.ThLamp;
import com.web709.service.ThLampService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/thlamp")
@Slf4j
@Api(tags = "走马灯")
public class ThLampController {
    @Autowired
    private ThLampService thLampService;

    @PostMapping
    @ApiOperation("添加文字")
    @ApiImplicitParam(name = "token", required = false, paramType = "header", dataType = "String")
    public R<String> save(@RequestBody ThLamp thLamp){
        thLampService.save(thLamp);
        return R.success("添加成功");
    }


    @GetMapping ("/{id}")
    @ApiOperation("单个查询")
    @ApiImplicitParam(name = "token", required = false, paramType = "header", dataType = "String")
    public R<ThLamp> getById(@PathVariable Integer id){
        ThLamp thLamp = thLampService.getById(id);
        return R.success(thLamp);
    }

    @GetMapping("all")
    @ApiOperation("查询所有")
    @ApiImplicitParam(name = "token", required = false, paramType = "header", dataType = "String")
    public R<List<ThLamp>> getAll(){
        List<ThLamp> list = thLampService.list();
        return R.success(list);
    }

    @PutMapping("/update")
    @ApiOperation("修改文字")
    @ApiImplicitParam(name = "token", required = false, paramType = "header", dataType = "String")
    public R update(@RequestBody ThLamp thLamp){
        thLampService.updateById(thLamp);
        return R.success("修改成功啦");
    }

    @DeleteMapping
    @ApiOperation("删除文字")
    @ApiImplicitParam(name = "token", required = false, paramType = "header", dataType = "String")
    public R delete(@RequestBody List<Integer> ids){
        thLampService.removeByIds(ids);
        return R.success("删除成功");
    }



}
